import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'chat_item.dart';

class ChatList extends StatelessWidget {
  final bool isFriend;

  const ChatList({required this.isFriend});

  @override
  Widget build(BuildContext context) {
    final List<Map<String, dynamic>> chatData = isFriend
        ? [
            {
              'name': 'ANNA',
              'message': 'There is a new message',
              'time': '15:23',
              'hasNewMessage': true,
            },
            {
              'name': 'ANNA',
              'message': 'hello!',
              'time': '15:23',
              'hasNewMessage': false,
            },
            {
              'name': 'Lily',
              'message': 'hello!',
              'time': '15:23',
              'hasNewMessage': false,
            },
            {
              'name': 'Lily',
              'message': 'hello!',
              'time': '15:23',
              'hasNewMessage': true,
            },
          ]
        : [
            {
              'name': 'Sarah',
              'message': 'Nice to meet you!',
              'time': '16:30',
              'hasNewMessage': true,
            },
            {
              'name': 'Emma',
              'message': 'How are you?',
              'time': '16:28',
              'hasNewMessage': false,
            },
            {
              'name': 'Sophie',
              'message': 'I like your photos!',
              'time': '16:25',
              'hasNewMessage': true,
            },
            {
              'name': 'Olivia',
              'message': 'Can we be friends?',
              'time': '16:20',
              'hasNewMessage': false,
            },
          ];

    return ListView.separated(
      shrinkWrap: true,
      physics: const ClampingScrollPhysics(),
      padding: EdgeInsets.only(top: 10.h),
      itemCount: chatData.length,
      separatorBuilder: (context, index) => Padding(
        padding: EdgeInsets.symmetric(horizontal: 30.w),
        child: Divider(
          height: 1.h,
          color: Colors.white.withOpacity(0.1),
        ),
      ),
      itemBuilder: (context, index) {
        final chat = chatData[index];
        return ChatItem(
          name: chat['name'],
          message: chat['message'],
          time: chat['time'],
          hasNewMessage: chat['hasNewMessage'],
          isFirst: index == 0,
        );
      },
    );
  }
}
